class ShopInfo {
  final String shopname;
  final String shopnumber;
  final num shopID;

  ShopInfo({this.shopID, this.shopname, this.shopnumber});

  factory ShopInfo.init(Map<String, dynamic> json) {
    return ShopInfo(
        shopID: json['shopID'],
        shopname: json['name'],
        shopnumber: json['phone_number']);
  }
}

class UserInfo {
  final String name;
  final String address;
  final String phone;

  UserInfo({this.address, this.name, this.phone});

  factory UserInfo.init(Map<String, dynamic> json) {
    return UserInfo(
        name: json['name'], address: json['address'], phone: json['phone']);
  }
}

class MedicineItem {
  final num number;
  final String mainpicture;
  final num price;
  final String medicinename;

  MedicineItem({this.number, this.mainpicture, this.price, this.medicinename});
  factory MedicineItem.init(Map<String, dynamic> json) {
    return MedicineItem(
        number: json['number'],
        mainpicture: json['mainpicture'],
        price: json['price'],
        medicinename: json['medicine_name']);
  }
}

class OrderItem {
  final num id; //订单状态
  final num allPrice;
  final String time; //下单时间
  final num deliveryFee;
  List<MedicineItem> medicineItem;
  ShopInfo shop;
  UserInfo user;

  OrderItem(
      {this.id,
      this.allPrice,
      this.time,
      this.deliveryFee,
      this.medicineItem,
      this.shop,
      this.user});

  factory OrderItem.init(Map<String, dynamic> json) {
    List<MedicineItem> getList(list) {
      List<MedicineItem> arr = [];
      print(list);
      list.forEach((dynamic item) {
        arr.add(MedicineItem.init(item));
      });
      return arr;
    }

    return OrderItem(
        id: json['id'],
        allPrice: json['allPrice'],
        time: json['time'],
        deliveryFee: json['deliverFee'],
        shop: ShopInfo.init(json['shop']),
        user: UserInfo.init(json['user_info']),
        medicineItem: getList(json['medicine_list']));
  }
}
